package com.ruoyi.web.controller.barcode;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BarcodeField;
import com.ruoyi.system.service.IBarcodeFieldService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 条码字段Controller
 * 
 * @author ruoyi
 * @date 2025-03-26
 */
@RestController
@RequestMapping("/barcode/field")
public class BarcodeFieldController extends BaseController
{
    @Autowired
    private IBarcodeFieldService barcodeFieldService;

    /**
     * 查询条码字段列表
     */
    @PreAuthorize("@ss.hasPermi('barcode:field:list')")
    @GetMapping("/list")
    public TableDataInfo list(BarcodeField barcodeField)
    {
        startPage();
        List<BarcodeField> list = barcodeFieldService.selectBarcodeFieldList(barcodeField);
        return getDataTable(list);
    }

    /**
     * 导出条码字段列表
     */
    @PreAuthorize("@ss.hasPermi('barcode:field:export')")
    @Log(title = "条码字段", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BarcodeField barcodeField)
    {
        List<BarcodeField> list = barcodeFieldService.selectBarcodeFieldList(barcodeField);
        ExcelUtil<BarcodeField> util = new ExcelUtil<BarcodeField>(BarcodeField.class);
        util.exportExcel(response, list, "条码字段数据");
    }

    /**
     * 获取条码字段详细信息
     */
    @PreAuthorize("@ss.hasPermi('barcode:field:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(barcodeFieldService.selectBarcodeFieldById(id));
    }

    /**
     * 新增条码字段
     */
    @PreAuthorize("@ss.hasPermi('barcode:field:add')")
    @Log(title = "条码字段", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BarcodeField barcodeField)
    {
        barcodeField.setCreatedBy(getUsername());
        return toAjax(barcodeFieldService.insertBarcodeField(barcodeField));
    }

    /**
     * 修改条码字段
     */
    @PreAuthorize("@ss.hasPermi('barcode:field:edit')")
    @Log(title = "条码字段", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BarcodeField barcodeField)
    {
        barcodeField.setModifiedBy(getUsername());
        barcodeField.setModifiedDate(new Date());
        return toAjax(barcodeFieldService.updateBarcodeField(barcodeField));
    }

    /**
     * 删除条码字段
     */
    @PreAuthorize("@ss.hasPermi('barcode:field:remove')")
    @Log(title = "条码字段", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(barcodeFieldService.deleteBarcodeFieldByIds(ids));
    }
}
